package com.kasax.httpsupport;

import java.io.IOException;

public class HttpTask implements Runnable {

    private HttpCall httpCall;
    private Callback callback;
    private IRequestHandler requestHandler;
    private IResponseHandler handler = IResponseHandler.RESPONSE_HANDLER;

    public HttpTask(HttpCall httpCall, Callback callback, IRequestHandler requestHandler) {
        this.httpCall = httpCall;
        this.callback = callback;
        this.requestHandler = requestHandler;
    }

    @Override
    public void run() {
        try {
            Response response = requestHandler.handlerRequest(httpCall);
            handler.handlerSuccess(callback, response);
        } catch (IOException e) {
            handler.handleFail(callback, httpCall.request, e);
            e.printStackTrace();
        }
    }
}
